public final class IndexedSprite extends Renderer2D {
	public byte[] pixels;
	public int[] palette;
	public int width;
	public int anInt1519;
	public int anInt1520;
	public int anInt1521;
	public int anInt1522;
	public int anInt1523;

	public IndexedSprite(Archive archive, String name, int index) {
		Packet packet = new Packet(archive.method154(name
			+ ".dat", null));
		Packet packet_0_ = new Packet(archive.method154(
			"index.dat", null));
		packet_0_.offset = packet.getUShort();
		anInt1522 = packet_0_.getUShort();
		anInt1523 = packet_0_.getUShort();
		int i_1_ = packet_0_.getUByte();
		palette = new int[i_1_];
		for (int i_2_ = 0; i_2_ < i_1_ - 1; i_2_++) {
			palette[i_2_ + 1] = packet_0_.get24BitInt1();
		}
		for (int i_3_ = 0; i_3_ < index; i_3_++) {
			packet_0_.offset += 2;
			packet.offset += (packet_0_.getUShort() * packet_0_
				.getUShort());
			packet_0_.offset++;
		}
		anInt1520 = packet_0_.getUByte();
		anInt1521 = packet_0_.getUByte();
		width = packet_0_.getUShort();
		anInt1519 = packet_0_.getUShort();
		int i_4_ = packet_0_.getUByte();
		int i_5_ = width * anInt1519;
		pixels = new byte[i_5_];
		if (i_4_ == 0) {
			for (int i_6_ = 0; i_6_ < i_5_; i_6_++) {
				pixels[i_6_] = packet.getByte();
			}
		} else if (i_4_ == 1) {
			for (int i_7_ = 0; i_7_ < width; i_7_++) {
				for (int i_8_ = 0; i_8_ < anInt1519; i_8_++) {
					pixels[i_7_ + i_8_ * width] = packet.getByte();
				}
			}
		}
	}

	public void method496(int i) {
		anInt1522 /= 2;
		anInt1523 /= 2;
		byte[] is = new byte[anInt1522 * anInt1523];
		int i_9_ = 0;
		if (i == 0) {
			for (int i_10_ = 0; i_10_ < anInt1519; i_10_++) {
				for (int i_11_ = 0; i_11_ < width; i_11_++) {
					is[((i_11_ + anInt1520 >> 1) + (i_10_ + anInt1521 >> 1) * anInt1522)] = pixels[i_9_++];
				}
			}
			pixels = is;
			width = anInt1522;
			anInt1519 = anInt1523;
			anInt1520 = 0;
			anInt1521 = 0;
		}
	}

	public void method497() {
		if (width != anInt1522 || anInt1519 != anInt1523) {
			byte[] is = new byte[anInt1522 * anInt1523];
			int i = 0;
			for (int i_12_ = 0; i_12_ < anInt1519; i_12_++) {
				for (int i_13_ = 0; i_13_ < width; i_13_++) {
					is[i_13_ + anInt1520 + (i_12_ + anInt1521) * anInt1522] = pixels[i++];
				}
			}
			pixels = is;
			width = anInt1522;
				anInt1519 = anInt1523;
				anInt1520 = 0;
				anInt1521 = 0;
		}
	}

	public void method498() {
		byte[] is = new byte[width * anInt1519];
		int i_14_ = 0;
		for (int i_15_ = 0; i_15_ < anInt1519; i_15_++) {
			for (int i_16_ = width - 1; i_16_ >= 0; i_16_--) {
				is[i_14_++] = pixels[i_16_ + i_15_ * width];
			}
		}
		pixels = is;
			anInt1520 = anInt1522 - width - anInt1520;
	}

	public void method499() {
		byte[] is = new byte[width * anInt1519];
		int i_17_ = 0;
		for (int i_18_ = anInt1519 - 1; i_18_ >= 0; i_18_--) {
			for (int i_19_ = 0; i_19_ < width; i_19_++) {
				is[i_17_++] = pixels[i_19_ + i_18_ * width];
			}
		}
		pixels = is;
		anInt1521 = anInt1523 - anInt1519 - anInt1521;
	}

	public void method500(int i, int i_20_, int i_21_) {
		for (int i_23_ = 0; i_23_ < palette.length; i_23_++) {
			int i_24_ = palette[i_23_] >> 16 & 0xff;
			i_24_ += i_21_;
			if (i_24_ < 0) {
				i_24_ = 0;
			} else if (i_24_ > 255) {
				i_24_ = 255;
			}
			int i_25_ = palette[i_23_] >> 8 & 0xff;
			i_25_ += i_20_;
			if (i_25_ < 0) {
				i_25_ = 0;
			} else if (i_25_ > 255) {
				i_25_ = 255;
			}
			int i_26_ = palette[i_23_] & 0xff;
			i_26_ += i;
			if (i_26_ < 0) {
				i_26_ = 0;
			} else if (i_26_ > 255) {
				i_26_ = 255;
			}
			palette[i_23_] = (i_24_ << 16) + (i_25_ << 8) + i_26_;
		}
	}

	public void method501(int i, int i_27_) {
		i_27_ += anInt1520;
		i += anInt1521;
		int i_30_ = i_27_ + i * Renderer2D.width;
		int i_31_ = 0;
		int i_32_ = anInt1519;
		int i_33_ = width;
		int i_34_ = Renderer2D.width - i_33_;
		int i_35_ = 0;
		if (i < Renderer2D.topY) {
			int i_36_ = Renderer2D.topY - i;
			i_32_ -= i_36_;
			i = Renderer2D.topY;
			i_31_ += i_36_ * i_33_;
			i_30_ += i_36_ * Renderer2D.width;
		}
		if (i + i_32_ > Renderer2D.bottomY) {
			i_32_ -= i + i_32_ - Renderer2D.bottomY;
		}
		if (i_27_ < Renderer2D.topX) {
			int i_37_ = Renderer2D.topX - i_27_;
			i_33_ -= i_37_;
			i_27_ = Renderer2D.topX;
			i_31_ += i_37_;
			i_30_ += i_37_;
			i_35_ += i_37_;
			i_34_ += i_37_;
		}
		if (i_27_ + i_33_ > Renderer2D.bottomX) {
			int i_38_ = i_27_ + i_33_ - Renderer2D.bottomX;
			i_33_ -= i_38_;
			i_35_ += i_38_;
			i_34_ += i_38_;
		}
		if (i_33_ > 0 && i_32_ > 0) {
			method502(i_31_, Renderer2D.pixels, pixels, i_35_,
 palette, i_32_,
				i_33_, i_30_, i_34_);
		}
	}

	private void method502(int i, int[] is, byte[] is_39_, int i_40_, int[] is_41_, int i_42_,
		int i_43_, int i_44_, int i_45_) {
		int i_46_ = -(i_43_ >> 2);
		i_43_ = -(i_43_ & 0x3);
		for (int i_47_ = -i_42_; i_47_ < 0; i_47_++) {
			for (int i_48_ = i_46_; i_48_ < 0; i_48_++) {
				int i_49_ = is_39_[i++];
				if (i_49_ != 0) {
					is[i_44_++] = is_41_[i_49_ & 0xff];
				} else {
					i_44_++;
				}
				i_49_ = is_39_[i++];
				if (i_49_ != 0) {
					is[i_44_++] = is_41_[i_49_ & 0xff];
				} else {
					i_44_++;
				}
				i_49_ = is_39_[i++];
				if (i_49_ != 0) {
					is[i_44_++] = is_41_[i_49_ & 0xff];
				} else {
					i_44_++;
				}
				i_49_ = is_39_[i++];
				if (i_49_ != 0) {
					is[i_44_++] = is_41_[i_49_ & 0xff];
				} else {
					i_44_++;
				}
			}
			for (int i_50_ = i_43_; i_50_ < 0; i_50_++) {
				int i_51_ = is_39_[i++];
				if (i_51_ != 0) {
					is[i_44_++] = is_41_[i_51_ & 0xff];
				} else {
					i_44_++;
				}
			}
			i_44_ += i_45_;
			i += i_40_;
		}
	}
}
